<?php
// full path to kb directory, if it does no work write it manually
$app_dir = str_replace(array('\\', '/client/cron/'), '/', getcwd() . '/');

$admin_dir  = $app_dir . 'admin/';
$client_dir = $app_dir . 'client/inc/';
$cron_dir   = $app_dir . 'client/cron/';

$filename   = $app_dir . 'kb.rss';


require_once $admin_dir . 'config.inc.php';

if(!isset($_SERVER['DOCUMENT_ROOT'])) {
	echo 'You should manually specify $_SERVER["DOCUMENT_ROOT"] in admin/config.inc.php' . "\n";
}


require_once $cron_dir . 'cron_common.php';
require_once 'eleontev/XML/RSSCreator.php';

require_once $client_dir . 'KBClientController.php';
require_once $client_dir . 'KBClientRSSModel.php';
require_once $client_dir . 'DocumentParser.php';


$manager = &new KBClientRSSModel();
$setting =&$manager->getSettings();
$entries = &$manager->getEntries();

if($entries) {

	$controller = &new KBClientController();
	$controller->kb_path = APP_CLIENT_PATH;
	$controller->setModRewrite(false);

	$rss = &new RSSCreator();
	$rss->setEncoding($conf['lang']['meta_charset']);
	$rss->setChannel('title', $setting['rss_title']);
	$rss->setChannel('link', APP_CLIENT_PATH);
	$rss->setChannel('description', $setting['rss_description']);
	
	foreach($entries as $k => $v) {
		$link = $controller->getLink('entry', $v['category_id'], $v['entry_id']);
		$rss->setItem($v['title'], $link, $v);
	}
	echo "<pre>"; print_r($filename); echo "</pre>";
	FileUtil::write($filename, $rss->getXML());
	//echo $rss->getXML(true);
}


?>